using System;
using System.Collections.Generic;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.Hr.Bill;
using TiaoTaoHelper.Wtm.Models;


namespace HengTong.ViewModel.Hr.SysHrJobAssignmentRequestBillEntryVms
{
    public partial class SysHrJobAssignmentRequestBillEntryListVm : BaseListVm<SysHrJobAssignmentRequestBillEntryView,
        SysHrJobAssignmentRequestBillEntrySearcher>
    {
        protected override IEnumerable<IGridColumn<SysHrJobAssignmentRequestBillEntryView>> InitGridHeader()
        {
            return new List<GridColumn<SysHrJobAssignmentRequestBillEntryView>>
            {
                this.MakeGridHeader(x => x.PersonName),
                this.MakeGridHeader(x => x.StaffNo),
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.JobPositionName),
                this.MakeGridHeader(x => x.GroupName),
                this.MakeGridHeader(x => x.OrgName),
                this.MakeGridHeader(x => x.EntryRemark),
                this.MakeGridHeader(x => x.JobAssignmentName),
                this.MakeGridHeader(x => x.WorkflowStatus),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysHrJobAssignmentRequestBillEntryView> GetSearchQuery()
        {
            var query = DC.Set<SysHrJobAssignmentRequestBillEntry>()
                .CheckEqual(Searcher.PersonId, x => x.PersonId)
                .CheckContain(Searcher.StaffNo, x => x.StaffNo)
                .CheckContain(Searcher.Name, x => x.Name)
                .CheckEqual(Searcher.JobPositionId, x => x.JobPositionId)
                .CheckEqual(Searcher.GroupId, x => x.GroupId)
                .CheckEqual(Searcher.OrgId, x => x.OrgId)
                .CheckEqual(Searcher.JobAssignmentId, x => x.JobAssignmentId)
                .Select(x => new SysHrJobAssignmentRequestBillEntryView
                {
                    ID = x.ID,
                    PersonName = x.Person.Name,
                    StaffNo = x.StaffNo,
                    Name = x.Name,
                    JobPositionName = x.JobPosition.Name,
                    GroupName = x.Group.GroupName,
                    OrgName = x.Org.Name,
                    EntryRemark = x.EntryRemark,
                    JobAssignmentName = x.JobAssignment.BillCode,
                    WorkflowStatus = x.JobAssignment.WorkflowStatus
                })
                .OrderByDescending(x => x.JobAssignmentName);
            return query;
        }
    }

    public class SysHrJobAssignmentRequestBillEntryView : SysHrJobAssignmentRequestBillEntry
    {
        [Display(Name = "姓名")] public String PersonName { get; set; }
        [Display(Name = "岗位名称")] public String JobPositionName { get; set; }
        [Display(Name = "_Admin.GroupName")] public String GroupName { get; set; }
        [Display(Name = "组织名称")] public String OrgName { get; set; }
        [Display(Name = "单据编号")] public String JobAssignmentName { get; set; }
        [Display(Name = "工作流状态")] public WorkflowStatus? WorkflowStatus { get; set; }
    }
}